import sys
import os


def pip_install(libraries):
    """判断是否安装了库 没有就直接pip安装"""
    for library in libraries:
        library = library.split(".")[0]
        try:
            __import__(library)
            print(f"{library} 已安装")
        except ImportError:
            print(f"{library} 没有安装，请运行以下代码")
            print(f"!pip install -i http://mirrors.aliyun.com/pypi/simple {library}")


def 环境初始化():
    pip_install(["svgwrite", "cairosvg"])
    current_dir = os.path.dirname(os.path.abspath(''))
    sys.path.append(current_dir)


if __name__ == '__main__':
    pip_install(["svgwrite", "cairosvg"])
